﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapData {
    
    public class SimplePoint {
        
        private double x;
        private double y;


        /// <summary>
        /// pre:
        /// post: Creates a SimplePoint object
        /// </summary>
        public SimplePoint() {
            x = 0;
            y = 0;
        }


        /// <summary>
        /// pre:
        /// post: Returns or sets the x coordinate of the point.
        /// </summary>
        public double X {
            get {
                return this.x;
            }
            set{
                this.x = value;
            }
        }

        /// <summary>
        /// pre:
        /// post: Returns or sets the y coordinate of the point.
        /// </summary>
        public double Y {
            get {
                return this.y;
            }
            set {
                this.y = value;
            }
        }

        /// <summary>
        /// pre:
        /// post:  Returns the point as a string.
        /// </summary>
        /// <returns></returns>
        public override string ToString() {
            return (this.x + "," + this.y);
        }
        
        /// <summary>
        /// pre: A valid string needs to be created and passed to the function
        /// post: Sets the coordinate values of the simplepoint
        /// </summary>
        /// <param name="value"></param>
        /// <param name="delimiter"></param>
        /// <returns></returns>
        public bool tryParse(string value, string delimiter) {
            
            string[] values = value.Split(delimiter.ToCharArray());
            if (values.Length>=2) {
                double orginalX = this.x;
                if (!double.TryParse(values[0], out this.x)) {
                    return false;
                }
                if (!double.TryParse(values[1], out this.y)) {
                    this.x = orginalX;
                    return false;
                }
                return true;

            }
            return false;
        }        
    }
}
